public class p2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int limit = 4000000;
		int sum = 0;

		int fib_prev = 1;
		int fib_curr = 2;
		int tmp;

		while (fib_curr < limit) {
			if (fib_curr % 2 == 0) {
				sum += fib_curr;
			}

			tmp = fib_curr;
			fib_curr = fib_prev + fib_curr;
			fib_prev = tmp;
		}
		System.out.println(sum);

		// advanced method
		sum = 0;
		int a = 1;
		int b = 1;
		int c = a + b; // always third number is even.

		while (c < limit) {
			sum += c;
			a = b + c;
			b = c + a;
			c = a + b;
		}
		System.out.println(sum);
	}
}
